﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MainQuoteDBModel;
using CMSModel;

public partial class news_NewsReBK_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            MainQuoteDBEntities dal = new MainQuoteDBEntities();
            var lst = dal.TB_BK.Where(x => x.BK_CODE.StartsWith("002"));
            Repeater1.DataSource = lst;
            Repeater1.DataBind();
        }
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        string str = ddlType.SelectedValue;
        if (str == "hy")
        {
            MainQuoteDBEntities dal = new MainQuoteDBEntities();
            var lst = dal.TB_BK.Where(x => x.BK_CODE.StartsWith("002") && !string.IsNullOrEmpty(x.BK_NAME));
            Repeater1.DataSource = lst;
            Repeater1.DataBind();
        }
        else if (str == "dq")
        {
            MainQuoteDBEntities dal = new MainQuoteDBEntities();
            var lst = dal.TB_BK.Where(x => x.BK_CODE.StartsWith("003") && !string.IsNullOrEmpty(x.BK_NAME));
            Repeater1.DataSource = lst;
            Repeater1.DataBind();
        }
        else if (str == "gn")
        {
            MainQuoteDBEntities dal = new MainQuoteDBEntities();
            var lst = dal.TB_BK.Where(x => x.BK_CODE.StartsWith("001") && !string.IsNullOrEmpty(x.BK_NAME));
            Repeater1.DataSource = lst;
            Repeater1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MainQuoteDBModel.MainQuoteDBEntities mDal = new MainQuoteDBModel.MainQuoteDBEntities();
        var bkLst= mDal.TB_BK.ToList();
        CMSModel.CMSEntities cms = new CMSModel.CMSEntities();
        foreach (var c in bkLst)
        {
            NewsReBK n = new NewsReBK();
            n.BkId = c.BK_CODE;
            n.Key = c.BK_NAME;
            if (!cms.NewsReBK.Any(x => x.BkId == n.BkId && x.Key == c.BK_NAME))
            {
                cms.NewsReBK.AddObject(n);
            }
        }
        cms.SaveChanges();
    }
}